#include"Telephone.h"
#include<stdlib.h>
#include<string.h>
#include<stdio.h>

struct Telephone
{
    char *name;
    char *number;
};

bool CompareName(void *p1, void *p2)
{
    Tel *s1=(Tel *)p1;
    Tel *s2=(Tel *)p2;
    return strcmp(s1->name,s2->name)>0;
}

bool GreatName(void *p1, void *p2)
{
    Tel *s1=(Tel *)p1;
    char *s2=(char *)p2;
    return strcmp(s1->name,s2)>0;
}

bool GreatName2(void *p1, void *p2)
{
    char *s1=(char *)p1;
    Tel *s2=(Tel *)p2;
    return strcmp(s1,s2->name)>0;
}

bool IsNameEqual(void *p1, void *p2)
{
    Tel *s= (Tel *)p1;
    const char *str=(const char *)p2;
    return strcmp(s->name, str)==0;
}

bool IsNumberEqual(void *p1, void *p2)
{
    Tel *s= (Tel *)p1;
    const char *str=(const char *)p2;
    return strcmp(s->number, str)==0;
}

Tel* InitTel(char *name, char *number)
{
    Tel *t=(Tel *)malloc(sizeof(Tel));
    if(t==NULL)
    {
        printf("InitTel malloc error\n");
        return NULL;
    }
    else
    {
        t->name=strdup(name);
        t->number=strdup(number);
        return t;
    }
}

void FreeTel(void* ptr)
{
    Tel *t=(Tel *)ptr;
    free(t->name);
    free(t->number);
    free(t);
}

void PrintTel(void* ptr)
{
    Tel *t=(Tel *)ptr;
    printf("%s  %s\n",t->name,t->number);
}

